/** @format */

import {
    _decorator,
    Component,
    EPhysics2DDrawFlags,
    instantiate,
    Layers,
    Node,
    PhysicsSystem2D,
    Prefab,
    UITransform,
} from "cc";
import { app } from "db://assets/FrameWork/App";
import { cCollider } from "db://assets/FrameWork/Module/Collision/Collider";
import { ColliderObject } from "db://assets/FrameWork/Module/Collision/ColliderObject";
import { BaseUI } from "db://assets/FrameWork/Module/Component/BaseUI";
import { nsBundleConst } from "../../../Const/BundleConst";
import { myGame } from "../../../MyGame";
const { ccclass, property } = _decorator;

@ccclass("BattleUI")
export class BattleUI extends BaseUI {
    @property({ type: Node, displayName: "战斗节点" })
    nodeBattle: Node = null;
    private _tickTimer = -1;

    protected init(): void {}
    protected onShow(): void {
        super.onShow();
        myGame.battleMgr.init();
        myGame.battleMgr.bulletLayer = this.nodeBattle.getChildByName("layerBullet");
        myGame.battleMgr.utfBulletLayer = myGame.battleMgr.bulletLayer.getComponent(UITransform);
        myGame.battleMgr.entityLayer = this.nodeBattle.getChildByName("layerEntity");
        // this.scheduleOnce(() => {
        this._onGameStart();
        // }, 0);
    }

    private _onGameStart(): void {
        this._tickTimer = app.timerMgr.schedule(this.tick, this, null, 0, -1, 0);
        app.inputMgr.open();
        this._createHero();
    }

    private _createHero() {
        app.entityMgr.add("1001", "Entity", (node) => {
            node.setPosition(0, -500, 0);
            myGame.battleMgr.entityLayer.addChild(node);
        });
        return;
    }
    tick(dt: number): void {
        // app.rapierMgr.step(dt);
        app.tickMgr.tick(dt);
        cCollider.inst.update(dt);
    }
    public onHide(): void {
        super.onHide();

        // PhysicsSystem2D.instance.enable = false;
    }
}
